import store from '../../service/store'
// import axios from '../../plugins/axios'
// import api from '../server'

import qs from 'qs'
let beforeEach = (to, from, next) => {
  store.commit('changeCurrentRoute', to)
  let code = qs.parse(qs.parse(window.location).search.replace('?', '')).code
  if (code && window.location.pathname !== '/auth') {
    // 是登录回调
    next('/auth' + qs.parse(window.location).search)
    // console.log('--------------------------------------' + code)
    // axios.get(api.github_login + '?' + qs.stringify({code: code})).then(({data}) => {
    //   console.log('success')
    //   // next('/')
    // })
  } else {
    let accessToken = store.getters.getAccessToken
    if (!accessToken && to.name !== 'login' && to.name !== 'auth') {
      // 还未登录 并且不是跳转到登录页面
      next('/')
    } else {
      next()
    }
  }
}
let afterEach = (to, from) => {
  console.log('afterEach')
}

export {
  afterEach,
  beforeEach
}
